<script>
	$(function() {
		$( "#txtNgaysinh" ).datepicker({dateFormat: 'dd-mm-yy'});
		$( "#txtNgaythamgia" ).datepicker({dateFormat: 'dd-mm-yy'});
	});
</script>
<?php
if (!defined('WEB_ROOT')) {
	exit;
}

// make sure matg exists
if (isset($_GET['id']) && $_GET['id'] > 0) {
	$id = (int)$_GET['id'];
} else {
	// redirect to index.php 
	header('Location: index.php');
}
if (isset($_GET['nhomnc_id']) && $_GET['nhomnc_id'] > 0) {
	$nhomnc_id = (int)$_GET['nhomnc_id'];
} 
if (isset($_GET['dv_id']) && $_GET['dv_id'] > 0) {
	$dv_id = (int)$_GET['dv_id'];
}
// Lấy thông tin tác giả
$sql = "SELECT tg.id, tg.matg, tg.hotentg, tg.ngaysinh, tg.quequantg, tg.dv_id, dv.dienthoai_dv, tg.chucvu, tg.diachi, tg.dienthoai, tg.email, tg.didong, 
		tg.hocham, tg.hocvi, tgn.nhomnc_id
        FROM tacgia tg left join donvi dv on tg.dv_id = dv.id left join tacgia_nhomnc tgn ON tg.id = tgn.tg_id
		WHERE tg.id = $id";
		
	$result = mysql_query($sql) or die('Không lấy được thông tin tác giả. ' . mysql_error());
	$row    = mysql_fetch_assoc($result);
	extract($row);
	$sql = "SELECT id, tennnc
				FROM nhomnc
				ORDER BY id";
		$result = dbQuery($sql) or die('Không lấy được thông tin nhóm tác giả. ' . mysql_error());
		
		$groups = array();
		$list = '';
		while($row = dbFetchArray($result)) {
			list($id_nnc, $name) = $row;
			$list .= "<option value=\"$id_nnc\"";
				if ($id_nnc == $nhomnc_id) {
					$list.= " selected";
				}
				$list .= ">$name</option>\r\n";
		}	
		
			$sql = "SELECT id, tendv
				FROM donvi
				ORDER BY id";
		$result = dbQuery($sql) or die('Không lấy được thông tin đơn vị' . mysql_error());
		
		$groups = array();
		$list2 = '';
		while($row = dbFetchArray($result)) {
			list($id_dv, $name) = $row;
			$list2 .= "<option value=\"$id_dv\"";
				if ($id_dv == $dv_id) {
					$list2.= " selected";
				}
				$list2 .= ">$name</option>\r\n";
		}	
?> 
<div class="onecolumn">
				<div class="header">
					<span>Sửa thông tin tác giả</span>
				</div>
				<br class="clear"/>
				<div class="content">
					<form action="processAuthor.php?action=modifyAuthor&id=<?php echo $id; ?>&nhomnc_id=<?php echo nhomnc_id; ?>" method="post" enctype="multipart/form-data" name="frmAddAuthor" id="frmAddAuthor">
					 <!--<p align="center" class="formTitle">Sửa thông tin tác giả</p>-->
					 
					<table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
					  <tr> 
						   <td width="140" class="label">Mã tác giả</td>
						   <td colspan="3" class="content"> <input name="txtMatg" type="text" class="box" id="txtMatg" readonly="true" style="background-color:#DADADA" value="<?php echo $matg; ?>" size="20" maxlength="20"></td>
					  </tr>
					  <tr> 
						   <td width="140" class="label">Họ tên tác giả</td>
						   <td colspan="3" class="content"> <input name="txtHotentg" type="text" class="box" id="txtHotentg" value="<?php echo $hotentg; ?>" size="50" maxlength="50"></td>
					  </tr>
					  <tr> 
						   <td width="140" class="label">Ngày sinh</td>
						   <td colspan="3" class="content"><input name="txtNgaysinh" type="text" id="txtNgaysinh" value="<?php echo $ngaysinh; ?>" size="20" maxlength="20" class="box"> </td>
					  </tr>
					  <tr> 
						   <td width="140" class="label">Quê quán</td>
						   <td colspan="3" class="content"><input name="txtQuequan" type="text" id="txtQuequan" value="<?php echo $quequantg; ?>" size="50" maxlength="50" class="box"> </td>
					  </tr>
					  <tr> 
							   
						   <td width="140" class="label">Đơn vị</td>
						   <td class="content"> <select name="cboDept" id="cboDept" class="box">
							<option value="" selected>-- Chọn đơn vị --</option>
								<?php
									echo $list2;
								?>	 
							</select>  
						   <td width="140" class="label"> Điện thoại đơn vị</span></td>
						   <td class="content"><input name="txtDienthoai_dv" type="text" id="txtDienthoai_dv" value="<?php echo $dienthoai_dv; ?>" size="20" maxlength="20" class="box" /></td>
					  </tr>
					  <tr> 
						   <td width="140" class="label">Chức vụ</td>
						   <td colspan="3" class="content"><input name="txtChucvu" type="text" id="txtChucvu" value="<?php echo $chucvu; ?>" size="50" maxlength="50" class="box"> </td>
					  </tr>
					  <tr> 
						   <td width="140" class="label">Địa chỉ liên lạc</td>
						   <td colspan="3" class="content"><input name="txtDiachi" type="text" id="txtDiachi" value="<?php echo $diachi; ?>" size="70" maxlength="70" class="box"> </td>
					  </tr>
					  <tr> 
						   <td width="140" class="label">Điện thoại nhà riêng</td>
						   <td colspan="3" class="content"><input name="txtDienthoai" type="text" id="txtDienthoai" value="<?php echo $dienthoai; ?>" size="20" maxlength="20" class="box"> </td>
					  </tr>
					  <tr> 
						   <td width="140" class="label">Điện thoại di động</td>
						   <td class="content"><input name="txtDTDD" type="text" id="txtDTDD" value="<?php echo $didong; ?>" size="20" maxlength="20" class="box"> </td>
						   <td class="label">Email</td>
						   <td class="content"><input name="txtEmail" type="text" id="txtEmail" value="<?php echo $email; ?>" size="30" maxlength="30" class="box" /></td>
					  </tr>
					  <tr> 
						   <td width="140" class="label">Học hàm</td>
						   <td class="content"><input name="txtHocham" type="text" id="txtHocham" value="<?php echo $hocham; ?>" size="20" maxlength="20" class="box"> </td>
						   <td class="label">Học vị</span></td>
						   <td class="content"><input name="txtHocvi" type="text" id="txtHocvi" value="<?php echo $hocvi; ?>" size="20" maxlength="20" class="box" /></td>
					  </tr>
					  <tr> 
						   <td width="140" class="label">Hình ảnh</td>
						   <td colspan="3" class="content"> <input name="fleImage" type="file" id="fleImage" class="box"></td>
					  </tr>
					  <tr> 
						   <td width="140" class="label">Nhóm nghiên cứu</td>
						   <td class="content"> <select name="cboGroup" id="cboGroup" class="box">
							<option value="" selected>-- Chọn nhóm nghiên cứu --</option>
								<?php
									echo $list;
								?>	 
							</select></td>
						   <td class="label">Ngày tham gia</td>
						   <td class="content"><input name="txtNgaythamgia" type="text" id="txtNgaythamgia" value="<?php echo $ngaythamgia; ?>" size="15" maxlength="15" class="box" /></td>
					  </tr>
					 </table>
					 <p align="center"> 
					  <input name="btnModifyAuthor" type="button" id="btnModifyAuthor" value="Lưu thay đổi" onClick="checkAddAuthorForm();" class="box">
					  &nbsp;&nbsp;<input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.location.href='index.php';" class="box">  
					 </p>
					</form>
	</div>
</div>